package com.bite.logistics.listener;

import com.bite.logistics.constant.Constants;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class TestListener {


//    @RabbitListener(queues = Constants.RETRY_QUEUE)
//    public void handlerRetryAuto(Message message) {
////      log.info("接受到消息，开始消费..., message: {}", new String(message.getBody()));
//        System.out.println("DeliveryTag值: " + message.getMessageProperties().getDeliveryTag());
//        int a = 5 / 0;
//        System.out.println("业务处理完毕！");
//    }

    @RabbitListener(queues = Constants.RETRY_QUEUE)
    public void handlerRetryManual(Message message, Channel channel) {
        log.info("接受到消息，开始消费..., message: {}", new String(message.getBody()));
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.out.println("DeliveryTag值: " + deliveryTag);
        try {
            int a = 5 / 0;
            channel.basicAck(deliveryTag, false);
        } catch (Exception e) {
            try {
                channel.basicNack(deliveryTag, false, true);
            } catch (Exception ex) {
                log.error("消息拒绝失败", ex);
            }
        }
        int a = 5 / 0;
        System.out.println("业务处理完毕！");
    }

}
